package cn.iocoder.yudao.module.train.dal.mysql.studentcourseperformance;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.train.dal.dataobject.connectDTO.StudentCoursePerformanceStudentDTO;
import cn.iocoder.yudao.module.train.dal.dataobject.student.StudentDO;
import cn.iocoder.yudao.module.train.dal.dataobject.studentcourseperformance.StudentCoursePerformanceDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.train.controller.admin.studentcourseperformance.vo.*;

/**
 * 学生课程作品 Mapper
 *
 * @author waynelam
 */
@Mapper
public interface StudentCoursePerformanceMapper extends BaseMapperX<StudentCoursePerformanceDO> {

//    default PageResult<StudentCoursePerformanceDO> selectPage(StudentCoursePerformancePageReqVO reqVO) {
//        return selectPage(reqVO, new LambdaQueryWrapperX<StudentCoursePerformanceDO>()
//                .eqIfPresent(StudentCoursePerformanceDO::getTeachingId, reqVO.getTeachingId())
//                .eqIfPresent(StudentCoursePerformanceDO::getStudentId, reqVO.getStudentId())
//                .eqIfPresent(StudentCoursePerformanceDO::getAttachment, reqVO.getAttachment())
//                .betweenIfPresent(StudentCoursePerformanceDO::getCreateTime, reqVO.getCreateTime())
//                .orderByDesc(StudentCoursePerformanceDO::getId));
//    }

    default PageResult<StudentCoursePerformanceStudentDTO> selectPage(StudentCoursePerformancePageReqVO reqVO) {
        Page<StudentCoursePerformanceStudentDTO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        MPJLambdaWrapper<StudentCoursePerformanceDO> wrapper = new MPJLambdaWrapper<StudentCoursePerformanceDO>()
                .selectAll(StudentCoursePerformanceDO.class)
                .select(StudentDO::getStudentName)
                .select(StudentDO::getStudentPhoneNumber)
                .leftJoin(StudentDO.class, on -> on
                        .eq(StudentDO::getId, StudentCoursePerformanceDO::getStudentId))
                .eqIfExists(StudentCoursePerformanceDO::getClassesId, reqVO.getClassesId())
                .eqIfExists(StudentCoursePerformanceDO::getStudentId, reqVO.getStudentId())
                .likeIfExists(StudentDO::getStudentName, reqVO.getStudentName())
                .orderByDesc(StudentCoursePerformanceDO::getId);
        IPage<StudentCoursePerformanceStudentDTO> resultPage = selectJoinPage(page, StudentCoursePerformanceStudentDTO.class, wrapper);
        return new PageResult<>(resultPage.getRecords(), resultPage.getTotal());
    }

    default StudentCoursePerformanceStudentDTO selectById(Integer studentId) {
        return selectJoinOne(StudentCoursePerformanceStudentDTO.class,
                new MPJLambdaWrapper<StudentCoursePerformanceDO>()
                        .selectAll(StudentCoursePerformanceDO.class)
                        .select(StudentDO::getStudentName)
                        .leftJoin(StudentDO.class, StudentDO::getId, StudentCoursePerformanceDO::getStudentId)
                        .eq(StudentCoursePerformanceDO::getId, studentId)
        );
    }

}
